import json
import pandas as pd
import matplotlib.pyplot as plt


df = pd.read_csv("sensorlog_angvel.csv")

df["timestamp"] = df["timestamp"] - df["timestamp"][0]

plt.plot(df["timestamp"], df["X"], label="X", color="r", linewidth=0.1)
plt.plot(df["timestamp"], df["Y"], label="Y", color="g", linewidth=0.1)
plt.plot(df["timestamp"], df["Z"], label="Z", color="b", linewidth=0.1)

f = open("markers.json")
markers = json.load(f)
f.close()

start = markers.pop(0)

color_map = {
    "like": "m",
    "slide": "c",
    "forward": "y",
    "click": "k"
}

for marker in markers:
    marker["time"] = marker["time"] - start["time"]
    tmp = df[df["timestamp"] < marker["time"] * 1000 + 500]
    tmp = tmp[tmp["timestamp"] > marker["time"] * 1000 - 500]
    marker_color = color_map[marker["text"]]
    plt.plot(tmp["timestamp"], tmp["X"], label=marker["text"], color=marker_color, linewidth=0.5)
    plt.plot(tmp["timestamp"], tmp["Y"], label=marker["text"], color=marker_color, linewidth=0.5)
    plt.plot(tmp["timestamp"], tmp["Z"], label=marker["text"], color=marker_color, linewidth=0.5)

plt.show()
